package com.sunlei.webtest.quickstart;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @Author: sun
 * @Description:
 * @Data: create in 21:15 2018/11/21
 * @Modfied by:
 */
public class Producter {
    public static void main(String[] args) throws IOException, TimeoutException {

        /** 1.创建一个connectionFactory 并进行配置*/
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("127.0.0.1");
        connectionFactory.setPort(5672);
        connectionFactory.setVirtualHost("/");
        /** 2.通过连接工厂创建连接 */
        Connection connection =  connectionFactory.newConnection();
        /** 3.通过connection创建channel*/
        Channel channel = connection.createChannel();
        /** 4.通过channel发送数据
         *  @1 exchange :exchange名称,如果为空默认为"\",此时的规则是找有没有与routingkey同名的队列进行投递
         *  @2 routingkey
         *  The default exchange is implicitly bound to every queue, with a routing key equal to the queue name.
         *  It is not possible to explicitly bind to, or unbind from the default exchange. It also cannot be deleted.
         * */
        channel.basicPublish("","test",null,"hello rabbitmq".getBytes());
        /** 5.记得记得关闭连接*/
        channel.close();
        connection.close();
    }
}
